<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     rwd_default
 */
?>
<?php /** @var Mage_Core_Block_Template $this */?>
<div <?php echo $this->getGridHtmlClass() ? ' class="' . $this->getGridHtmlClass() . '"' : ''?><?php echo $this->getGridHtmlCss() ? ' style="' . $this->getGridHtmlCss() . '"' : ''?>>

<?php if ($caption = $this->getGridCaption()): ?>
<h2 class="table-caption"><?php echo $this->escapeHtml($caption) ?></h2>
<?php endif ?>

<?php $gridElements = $this->getGridElements(); ?>
<?php if ($gridElements): ?>
    <?php echo $this->getChildHtml('pager'); ?>
    <table id="<?php echo $this->getGridHtmlId() ?>" class="data-table linearize-table-large">
<?php foreach ($this->getGridColumns() as $column):?>
        <col <?php $width = $this->getObjectData($column, 'width'); echo $width ? ' width="' . $width . '"' : '' ?>/>
<?php endforeach ?>
        <thead>
            <tr>
<?php foreach ($this->getGridColumns() as $column):
$nobr = $this->getObjectData($column, 'is_nobr') ? '<span class="nobr">%s</span>' : '%s';
$title = $this->getObjectData($column, 'title');
?>
                <th><?php echo $title ? sprintf($nobr, $this->escapeHtml($title)) : '&nbsp;' ?></th>
<?php endforeach ?>
            </tr>
        </thead>
        <tbody>
<?php foreach($gridElements as $row): ?>
            <tr>
<?php foreach ($this->getGridColumns() as $column):
$nobr = $this->getObjectData($column, 'is_nobr') ? '<span class="nobr">%s</span>' : '%s';
$index = $this->getObjectData($column, 'index');
$value = $this->getObjectData($row, $index);
$linkUrl = $this->getObjectData($row, "{$index}_link_url");
$linkAnchorText = $this->getObjectData($row, "{$index}_link_text");
$linkText = $linkUrl ? ($linkAnchorText ? $linkAnchorText : $value) : '';
$linkFormat = $linkUrl ? '<a href="%s">%s</a>' : '';
?>
                <td<?php $this->getObjectData($row, 'is_amount') ? ' class="a-right"' : '' ?> data-rwd-label="<?php echo $this->getObjectData($column, 'title') ?>"><?php
if ($linkFormat) {
    echo sprintf($nobr, sprintf($linkFormat, $this->escapeHtml($linkUrl), $this->escapeHtml($linkText)));
} else {
    echo sprintf($nobr, $this->escapeHtml($value));
}
                ?></td>
<?php endforeach ?>
            </tr>
<?php endforeach ?>
        </tbody>
    </table>
    <?php echo $this->getChildHtml('pager'); ?>
    <script type="text/javascript">decorateTable('<?php echo $this->getGridHtmlId() ?>')</script>
<?php else: ?>
    <p><?php echo $this->escapeHtml($this->getEmptyGridMessage()); ?></p>
<?php endif ?>
</div>
